#include  <string>
#include  <cstdio>
#include  <iostream>
using namespace std;

int main(int argc, char *argv[])
{
	string ss;
	char d;
	int m,sum=0;
	while( true )
	{
		cin >> ss;
		if( ss == "0" )
		{
			printf("%d\n",sum);
			sum = 0;
			//cin >> ss;
		}
		else if(ss == "#")
			break;
		else
		{
			int n;
			cin >> ss;
			scanf("%d %c",&m,&d);
			switch ( d )
			{
				case 'F' : 
					n = m * 2;
					break;
				case 'B' :
					n = m + (m+(m%2))/2;
					break;
				case 'Y' :
					n = m > 500 ? m : 500;
					break;
			}
			sum += n;
		}
	}
}
